package bean;

import java.util.HashSet;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.servlet.http.HttpSession;

@Named
@ApplicationScoped
public class ActiveSessionsStoreBean {

	private Set<HttpSession> activeSessions = new HashSet<>();
	
	public void addSession(HttpSession session) {
		if(!activeSessions.contains(session))
			activeSessions.add(session);
	}
	
	public void removeSession(HttpSession session) {
		activeSessions.remove(session);	
	}
	
	public void invalidateSession(String userName) {
		for(HttpSession s : activeSessions) {
			if(s.getAttribute("userName").equals(userName))
				s.invalidate();
		}
	}
	
}